module(
    name = "pachyderm",
    repo_name = "com_github_pachyderm_pachyderm",
)

bazel_dep(name = "aspect_bazel_lib", version = "2.8.1")
bazel_dep(name = "aspect_rules_jest", version = "0.22.0")
bazel_dep(name = "aspect_rules_js", version = "2.0.1")
bazel_dep(name = "aspect_rules_ts", version = "3.0.0")
bazel_dep(name = "circl", version = "1.3.8")
bazel_dep(name = "container_structure_test", version = "1.19.1")
bazel_dep(name = "gazelle", version = "0.38.0")
bazel_dep(name = "jsonnet_go", version = "0.20.0")
bazel_dep(name = "rules_distroless", version = "0.3.8")
bazel_dep(name = "rules_go", version = "0.50.1")
bazel_dep(name = "rules_multirun", version = "0.9.0")
bazel_dep(name = "rules_nodejs", version = "6.2.0")
bazel_dep(name = "rules_oci", version = "2.0.1")
bazel_dep(name = "rules_python", version = "0.35.0")
bazel_dep(name = "rules_python_gazelle_plugin", version = "0.35.0")  # Same version as rules_python

bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.nogo(nogo = "//:nogo")
go_sdk.download(
    name = "go_sdk",
    version = "1.23.1",
)
use_repo(go_sdk, "go_sdk")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "go.etcd.io/etcd/api/v3",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "go.etcd.io/etcd/server/v3",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "go.etcd.io/etcd/raft/v3",
)
go_deps.gazelle_override(
    build_file_generation = "on",
    directives = [
        "gazelle:exclude **/**_test.go",
        "gazelle:exclude examples",
        "gazelle:resolve go github.com/grpc-ecosystem/grpc-gateway/internal //internal",
        "gazelle:resolve go github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options //protoc-gen-swagger/options",
        "gazelle:proto disable_global",
    ],
    path = "github.com/grpc-ecosystem/grpc-gateway",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "github.com/determined-ai/determined/proto",
)
go_deps.module_override(
    patch_strip = 1,
    patches = [
        "//private:protoc-gen-validate.patch",
    ],
    path = "github.com/envoyproxy/protoc-gen-validate",
)
go_deps.gazelle_override(
    build_file_generation = "off",
    path = "github.com/envoyproxy/protoc-gen-validate",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "github.com/chrusty/protoc-gen-jsonschema",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "github.com/dexidp/dex",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "github.com/dexidp/dex/api/v2",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "github.com/docker/docker",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "github.com/grpc-ecosystem/go-grpc-middleware",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "github.com/opentracing/basictracer-go",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable_global",
    ],
    path = "sourcegraph.com/sourcegraph/appdash",
)

# These next two directives are necessary if google.golang.org/protobuf in go.mod is different from
# what rules_go bundles (see go/private/repositories.bzl for the version they use).
go_deps.gazelle_override(
    build_file_generation = "off",
    path = "google.golang.org/protobuf",
)
go_deps.module_override(
    patch_strip = 1,
    patches = [
        # This patch is from running: `gazelle -repo_root . -go_prefix google.golang.org/protobuf
        # -go_naming_convention import_alias -proto disable_global` in a checkout of
        # google.golang.org/protobuf corresponding to the version we use in go.mod.
        "//private:google-golang-org-protobuf.patch",
    ],
    path = "google.golang.org/protobuf",
)

# This is a program and not a module, but we depend on it since there aren't prebuilt binaries
# available.
go_deps.module(
    path = "google.golang.org/grpc/cmd/protoc-gen-go-grpc",
    sum = "h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=",
    version = "v1.3.0",
)

# These are dependencies necessary to build protoc-gen-jsonschema; they don't issue binary releases,
# and we can't import _ github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-json-schema because
# govulncheck does not like non-modules being imported (errors with "it's a program, not a module").
# Therefore, we can't keep a reference to it in a go file and so "go mod tidy" deletes the cmd-only
# dependencies from go.sum.  That makes them unavailable to Bazel builds, and thus we fail to build
# the command for //:make_proto.
go_deps.module(
    path = "github.com/alecthomas/jsonschema",
    sum = "h1:SM/PhkjhbeX1w/Jkv7dHFYDn2y4/88XZp3CIqVHsdcs=",
    version = "v0.0.0-20210918223802-a1d3f4b43d7b",
)
go_deps.module(
    path = "github.com/iancoleman/orderedmap",
    sum = "h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=",
    version = "v0.2.0",
)
go_deps.module(
    path = "github.com/iancoleman/strcase",
    sum = "h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=",
    version = "v0.2.0",
)

# These are dependencies necessary for running a local dex instance.
# Similar reasoning to above -- we need these to run //:dex
go_deps.module(
    path = "ariga.io/atlas",
    sum = "h1:GwdJbXydHCYPedeeLt4x/lrlIISQ4JTH1mRWuE5ZZ14=",
    version = "v0.19.1-0.20240203083654-5948b60a8e43",
)
go_deps.module(
    path = "entgo.io/ent",
    sum = "h1:EO3Z9aZ5bXJatJeGqu/EVdnNr6K4mRq3rWe5owt0MC4=",
    version = "v0.14.0",
)
go_deps.module(
    path = "github.com/go-openapi/inflect",
    sum = "h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=",
    version = "v0.19.0",
)
go_deps.module(
    path = "github.com/oklog/run",
    sum = "h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=",
    version = "v1.1.0",
)
use_repo(
    go_deps,
    "co_honnef_go_tools",
    "com_github_adrg_xdg",
    "com_github_alecthomas_jsonschema",
    "com_github_alecthomas_participle_v2",
    "com_github_alessio_shellescape",
    "com_github_alingse_asasalint",
    "com_github_aws_aws_lambda_go",
    "com_github_aws_aws_sdk_go",
    "com_github_breml_bidichk",
    "com_github_c_bata_go_prompt",
    "com_github_cevaris_ordered_map",
    "com_github_chmduquesne_rollinghash",
    "com_github_chrusty_protoc_gen_jsonschema",
    "com_github_coreos_go_oidc_v3",
    "com_github_data_dog_go_sqlmock",
    "com_github_determined_ai_determined_proto",
    "com_github_dexidp_dex",
    "com_github_dexidp_dex_api_v2",
    "com_github_dlmiddlecote_sqlstats",
    "com_github_docker_docker",
    "com_github_docker_go_connections",
    "com_github_docker_go_units",
    "com_github_dustin_go_humanize",
    "com_github_envoyproxy_protoc_gen_validate",
    "com_github_evanphx_json_patch",
    "com_github_fatih_camelcase",
    "com_github_fatih_color",
    "com_github_felixge_httpsnoop",
    "com_github_fsnotify_fsnotify",
    "com_github_fsouza_go_dockerclient",
    "com_github_go_logr_zapr",
    "com_github_go_openapi_inflect",
    "com_github_go_sql_driver_mysql",
    "com_github_golang_protobuf",
    "com_github_golangci_gofmt",
    "com_github_google_btree",
    "com_github_google_go_cmp",
    "com_github_google_gofuzz",
    "com_github_google_shlex",
    "com_github_google_uuid",
    "com_github_gordonklaus_ineffassign",
    "com_github_gorilla_mux",
    "com_github_grpc_ecosystem_go_grpc_middleware",
    "com_github_grpc_ecosystem_go_grpc_prometheus",
    "com_github_grpc_ecosystem_grpc_gateway_v2",
    "com_github_gruntwork_io_terratest",
    "com_github_hanwen_go_fuse_v2",
    "com_github_hashicorp_golang_lru_v2",
    "com_github_iancoleman_orderedmap",
    "com_github_iancoleman_strcase",
    "com_github_icholy_replace",
    "com_github_instrumenta_kubeval",
    "com_github_itchyny_gojq",
    "com_github_jackc_pgconn",
    "com_github_jackc_pgerrcode",
    "com_github_jackc_pgx_v4",
    "com_github_jirfag_go_printf_func_name",
    "com_github_jmoiron_sqlx",
    "com_github_json_iterator_go",
    "com_github_juju_ansiterm",
    "com_github_kisielk_errcheck",
    "com_github_klauspost_compress",
    "com_github_lib_pq",
    "com_github_mattn_go_isatty",
    "com_github_minio_minio_go_v6",
    "com_github_minio_minio_go_v7",
    "com_github_modern_go_reflect2",
    "com_github_nishanths_exhaustive",
    "com_github_oklog_run",
    "com_github_opencontainers_image_spec",
    "com_github_openpeedeep_depguard_v2",
    "com_github_opentracing_contrib_go_grpc",
    "com_github_opentracing_opentracing_go",
    "com_github_pachyderm_ohmyglob",
    "com_github_pachyderm_s2",
    "com_github_pkg_browser",
    "com_github_pkg_errors",
    "com_github_prometheus_client_golang",
    "com_github_prometheus_common",
    "com_github_prometheus_procfs",
    "com_github_pulumi_pulumi_aws_sdk_v5",
    "com_github_pulumi_pulumi_awsx_sdk",
    "com_github_pulumi_pulumi_eks_sdk",
    "com_github_pulumi_pulumi_kubernetes_sdk_v3",
    "com_github_pulumi_pulumi_postgresql_sdk_v3",
    "com_github_pulumi_pulumi_sdk_v3",
    "com_github_robfig_cron",
    "com_github_satori_go_uuid",
    "com_github_segmentio_analytics_go",
    "com_github_sirupsen_logrus",
    "com_github_spf13_cobra",
    "com_github_spf13_pflag",
    "com_github_stretchr_testify",
    "com_github_tdakkota_asciicheck",
    "com_github_timewasted_go_accept_headers",
    "com_github_tomarrell_wrapcheck_v2",
    "com_github_uber_jaeger_client_go",
    "com_github_vbauerster_mpb_v6",
    "com_github_wader_readline",
    "com_github_wcharczuk_go_chart",
    "com_github_zeebo_blake3",
    "com_github_zeebo_xxh3",
    "com_google_cloud_go_profiler",
    "dev_gocloud",
    "in_gopkg_yaml_v2",
    "in_gopkg_yaml_v3",
    "io_ariga_atlas",
    "io_entgo_ent",
    "io_etcd_go_etcd_api_v3",
    "io_etcd_go_etcd_client_v3",
    "io_etcd_go_etcd_server_v3",
    "io_k8s_api",
    "io_k8s_apimachinery",
    "io_k8s_client_go",
    "io_k8s_klog_v2",
    "io_k8s_kubectl",
    "io_k8s_sigs_kind",
    "io_k8s_sigs_yaml",
    "io_k8s_utils",
    "net_starlark_go",
    "org_golang_google_genproto_googleapis_rpc",
    "org_golang_google_grpc",
    "org_golang_google_grpc_cmd_protoc_gen_go_grpc",
    "org_golang_google_protobuf",
    "org_golang_x_crypto",
    "org_golang_x_exp",
    "org_golang_x_mod",
    "org_golang_x_net",
    "org_golang_x_oauth2",
    "org_golang_x_sync",
    "org_golang_x_sys",
    "org_golang_x_term",
    "org_golang_x_text",
    "org_golang_x_tools",
    "org_golang_x_vuln",
    "org_uber_go_atomic",
    "org_uber_go_automaxprocs",
    "org_uber_go_zap",
)

non_module_deps = use_extension("//private:extensions.bzl", "non_module_deps")
use_repo(
    non_module_deps,
    # *args is disallowed by the starlark compiler in MODULE.bazel files, so we have to name each
    # dependency twice; once here, and once in //private:repositories.bzl.
    "com_enterprisedb_get_postgresql_macos",
    "com_github_bazelbuild_bazel_watcher_ibazel_aarch64_linux",
    "com_github_bazelbuild_bazel_watcher_ibazel_aarch64_macos",
    "com_github_bazelbuild_bazel_watcher_ibazel_x86_64_linux",
    "com_github_bazelbuild_bazel_watcher_ibazel_x86_64_macos",
    "com_github_bufbuild_protoc_gen_validate_aarch64_linux",
    "com_github_bufbuild_protoc_gen_validate_aarch64_macos",
    "com_github_bufbuild_protoc_gen_validate_x86_64_linux",
    "com_github_bufbuild_protoc_gen_validate_x86_64_macos",
    "com_github_containers_skopeo_aarch64_linux",
    "com_github_containers_skopeo_aarch64_macos",
    "com_github_containers_skopeo_x86_64_linux",
    "com_github_containers_skopeo_x86_64_macos",
    "com_github_grafana_loki_logcli_aarch64_linux",
    "com_github_grafana_loki_logcli_aarch64_macos",
    "com_github_grafana_loki_logcli_x86_64_linux",
    "com_github_grafana_loki_logcli_x86_64_macos",
    "com_github_grafana_loki_loki_aarch64_linux",
    "com_github_grafana_loki_loki_aarch64_macos",
    "com_github_grafana_loki_loki_x86_64_linux",
    "com_github_grafana_loki_loki_x86_64_macos",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_aarch64_linux",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_aarch64_macos",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_ts_aarch64_linux",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_ts_aarch64_macos",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_ts_x86_64_linux",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_ts_x86_64_macos",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_x86_64_linux",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_grpc_gateway_x86_64_macos",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_openapiv2_aarch64_linux",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_openapiv2_aarch64_macos",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_openapiv2_x86_64_linux",
    "com_github_grpc_ecosystem_grpc_gateway_protoc_gen_openapiv2_x86_64_macos",
    "com_github_kubernetes_sigs_metrics_server_helm_chart",
    "com_github_protocolbuffers_protobuf_aarch64_linux",
    "com_github_protocolbuffers_protobuf_aarch64_macos",
    "com_github_protocolbuffers_protobuf_go_protoc_gen_go_aarch64_linux",
    "com_github_protocolbuffers_protobuf_go_protoc_gen_go_aarch64_macos",
    "com_github_protocolbuffers_protobuf_go_protoc_gen_go_x86_64_linux",
    "com_github_protocolbuffers_protobuf_go_protoc_gen_go_x86_64_macos",
    "com_github_protocolbuffers_protobuf_x86_64_linux",
    "com_github_protocolbuffers_protobuf_x86_64_macos",
    "com_github_pseudomuto_protoc_gen_doc_aarch64_linux",
    "com_github_pseudomuto_protoc_gen_doc_aarch64_macos",
    "com_github_pseudomuto_protoc_gen_doc_x86_64_linux",
    "com_github_pseudomuto_protoc_gen_doc_x86_64_macos",
    "com_github_yannh_kubeconform_aarch64_linux",
    "com_github_yannh_kubeconform_aarch64_macos",
    "com_github_yannh_kubeconform_x86_64_linux",
    "com_github_yannh_kubeconform_x86_64_macos",
    "com_github_yelp_dumb_init_aarch64_linux",
    "com_github_yelp_dumb_init_x86_64_linux",
    "io_k8s_dl_kubectl_aarch64_linux",
    "io_k8s_dl_kubectl_aarch64_macos",
    "io_k8s_dl_kubectl_x86_64_linux",
    "io_k8s_dl_kubectl_x86_64_macos",
    "io_k8s_sigs_kind_aarch64_linux",
    "io_k8s_sigs_kind_aarch64_macos",
    "io_k8s_sigs_kind_x86_64_linux",
    "io_k8s_sigs_kind_x86_64_macos",
    "org_uber_go_gopatch_aarch64_linux",
    "org_uber_go_gopatch_aarch64_macos",
    "org_uber_go_gopatch_x86_64_linux",
    "org_uber_go_gopatch_x86_64_macos",
    "sh_helm_aarch64_linux",
    "sh_helm_aarch64_macos",
    "sh_helm_x86_64_linux",
    "sh_helm_x86_64_macos",
)

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")

# Base of pachd release images.  Note: contains libc for postgres utilities we bundle.
oci.pull(
    name = "distroless",
    digest = "sha256:e5260be292def77bc70d03003f788f3d32c0796972ea1412d72cc0c843ab139a",
    image = "gcr.io/distroless/base-debian12",  # nonroot tag
    platforms = [
        "linux/amd64",
        "linux/arm64/v8",
    ],
)

# Base of worker release images.
oci.pull(
    name = "distroless-static",
    digest = "sha256:26f9b99f2463f55f20db19feb4d96eb88b056e0f1be7016bb9296a464a89d772",
    image = "gcr.io/distroless/static-debian12",  # nonroot tag
    platforms = [
        "linux/amd64",
        "linux/arm64/v8",
    ],
)

# Base of pachctl image.
oci.pull(
    name = "debian-slim",
    digest = "sha256:36e591f228bb9b99348f584e83f16e012c33ba5cad44ef5981a1d7c0a93eca22",
    image = "docker.io/library/debian",  # 12-slim tag
    platforms = [
        "linux/amd64",
        "linux/arm64/v8",
    ],
)

# Needed by kindenv tests.
oci.pull(
    name = "pause",
    digest = "sha256:927d98197ec1141a368550822d18fa1c60bdae27b78b0c004f705f548c07814f",
    image = "gcr.io/google-containers/pause",
    platforms = [
        "linux/amd64",
        "linux/arm64",
    ],
)

# Needed by kindenv.
oci.pull(
    name = "zot_amd64",
    digest = "sha256:e5a5be113155d1e0032e5d669888064209da95c107497524f8d4eac8ed50b378",
    image = "ghcr.io/project-zot/zot-linux-amd64",
)
oci.pull(
    name = "zot_arm64",
    digest = "sha256:370582183d29bf3b3604251d63cda48cb44c55e9622c8c13c605cba5f1b6cb21",
    image = "ghcr.io/project-zot/zot-linux-arm64",
)
use_repo(oci, "debian-slim", "debian-slim_linux_amd64", "debian-slim_linux_arm64_v8", "distroless", "distroless-static", "distroless-static_linux_amd64", "distroless-static_linux_arm64_v8", "distroless_linux_amd64", "distroless_linux_arm64_v8", "pause", "pause_linux_amd64", "pause_linux_arm64", "zot_amd64", "zot_arm64")

# Python
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    ignore_root_user_error = True,
    python_version = "3.9",
)

# Load in both the strict and dev requirements for the jupyter extension.
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "jupyter-pip-requirements",
    python_version = "3.9",
    requirements_lock = "//jupyter-extension:requirements-lock.txt",
)
pip.parse(
    hub_name = "jupyter-pip-requirements-dev",
    python_version = "3.9",
    requirements_lock = "//jupyter-extension:requirements-dev-lock.txt",
)
use_repo(pip, "jupyter-pip-requirements", "jupyter-pip-requirements-dev")

# Node
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
node.toolchain(
    name = "nodejs",
    node_version_from_nvmrc = "//console:.nvmrc",
)
use_repo(node, "nodejs")

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm", dev_dependency = True)
use_repo(pnpm, "pnpm")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
    name = "npm_console_backend",
    npm_package_lock = "//console/backend:package-lock.json",
    pnpm_lock = "//console/backend:pnpm-lock.yaml",
    verify_node_modules_ignored = "//:.bazelignore",
)
npm.npm_translate_lock(
    name = "npm_console_frontend",
    npm_package_lock = "//console/frontend:package-lock.json",
    pnpm_lock = "//console/frontend:pnpm-lock.yaml",
    verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm_console_backend", "npm_console_frontend")

# Typescript
rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True)
rules_ts_ext.deps()
use_repo(rules_ts_ext, "npm_typescript")

# bsdtar
bazel_lib_toolchains = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains")
bazel_lib_toolchains.tar()
use_repo(bazel_lib_toolchains, "bsd_tar_toolchains")

register_toolchains("@bsd_tar_toolchains//:all")

# Apt (for Postgres binaries, cacerts, etc)
apt = use_extension("@rules_distroless//apt:extensions.bzl", "apt")
apt.install(
    name = "apt",
    lock = "//private/apt:apt.lock.json",
    manifest = "//private/apt:apt.yaml",
    resolve_transitive = True,
)
use_repo(apt, "apt")
